LagOHLCindexday <- function (TS, k = 1) {
  if (!is.OHLC(TS)) {
    stop("Price series must contain Open, High, Low and Close.")
  }
  result <- cbind(lag(Op(TS), k), 
                  lag(Hi(TS), k), 
                  lag(Lo(TS), k), 
                  lag(Cl(TS), k), 
                  lag(TS[,"indexday"], k))
  colnames(result) <- c(paste(colnames(Op(TS)), k, sep = ".Lag."), 
                        paste(colnames(Hi(TS)), k, sep = ".Lag."), 
                        paste(colnames(Lo(TS)), k, sep = ".Lag."), 
                        paste(colnames(Cl(TS)), k, sep = ".Lag."),
                        "indexday")
  return(result)
}

# this function lags all columns of a xts object and preserves the colnames
LagMultiColumnXTS <- function (TS, k=1) {
  if (!is.xts(TS)) {
    stop("TS is no xts object")
  }
  cols <- colnames (TS)
  result <- lag(TS[,cols[1]], k)
  if (length(cols)>1) {
    for (i in 2:length(cols)) {
      result <- cbind(result, lag(TS[,cols[i]], k))
    }
  }
  return (result)
}